package com.zhushenwudi.hmutils.view;

import com.zhushenwudi.hmutils.ResourceTable;
import ohos.agp.components.Component;
import ohos.agp.components.LayoutScatter;
import ohos.agp.components.Text;
import ohos.agp.window.dialog.CommonDialog;
import ohos.app.Context;

public class WaitingDialogView {
    private static CommonDialog dialog;
    private static final int WIDTH = 400;
    private static final int HEIGHT = 300;

    public static void show(final Context context, String msg) {
        LayoutScatter scatter = LayoutScatter.getInstance(context);
        Component v = scatter.parse(ResourceTable.Layout_dialog_loading, null, false);
        v.setComponentSize(WIDTH, HEIGHT);
        Text tips = (Text) v.findComponentById(ResourceTable.Id_tv_tips);
        tips.setText(msg);
        dialog = new CommonDialog(context);
        dialog.setSize(v.getWidth(), v.getHeight());
        dialog.setContentCustomComponent(v);
        dialog.show();
    }

    public static void hide() {
        if (dialog != null && dialog.isShowing()) {
            dialog.destroy();
        }
    }
}